import {getVideoById} from "@/api/video";

export default {
    namespaced: true,
    state: {
        dialogFormVisible: false,
        dialogTitle: '',
        pageSize: 10,
        currentPage: 1,
        total: 0,
        // 修改添加的表单数据
        videoForm: {
            id: null,
            title: "" ,
            des: "" ,
            coverImg: "",
            videoUrl: "" ,
            remark: "" ,
            playNum: null ,
        },
        // 表格数据
        tableData: [],
        // 表格选中数据
        multipleSelection: [],
    },
    getters: {},
    mutations: {
        openDialogForm(state, value) {
            state.dialogFormVisible = value.dialogFormVisible;
            state.dialogTitle = value.dialogTitle;
        },
        EditVideo(state, value) {
            state.dialogFormVisible = value.dialogFormVisible;
            state.dialogTitle = value.dialogTitle;
            Object.keys(state.videoForm).forEach((key) => {
                state.videoForm[key] = value.videoForm[key]
            })
        }
    },
    actions: {
        editVideo(state, id) {
            getVideoById(id).then((res) => {
                var params = {
                    dialogFormVisible: true,
                    dialogTitle: "修改视频",
                    videoForm: res.data.data
                }
                state.commit("EditVideo", params);
            })
        }
    },
}
